package io.renren.modules.work.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.ConfigConstant;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.work.entity.ScWorkerEntity;
import io.renren.modules.work.service.ScWorkerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-05-08 23:01:13
 */
@RestController
@RequestMapping("work/scworker")
public class ScWorkerController {
    @Autowired
    private ScWorkerService scWorkerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("work:scworker:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = scWorkerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{workerid}")
    @RequiresPermissions("work:scworker:info")
    public R info(@PathVariable("workerid") String workerid){
		ScWorkerEntity scWorker = scWorkerService.getById(workerid);

        return R.ok().put("scWorker", scWorker);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("work:scworker:save")
    public R save(@RequestBody ScWorkerEntity scWorker){
        scWorker.setWorkerno(ConfigConstant.generateWorkerNo());
		scWorkerService.save(scWorker);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("work:scworker:update")
    public R update(@RequestBody ScWorkerEntity scWorker){
		scWorkerService.updateById(scWorker);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("work:scworker:delete")
    public R delete(@RequestBody String[] workerids){
		scWorkerService.removeByIds(Arrays.asList(workerids));

        return R.ok();
    }

}
